﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleBehaviorTreeLibrary
{
    class Program
    {
        private static Blackboard _blackboard;
        private static RobotBehaviorSelector _robotAI;
        private static Random _random;

        static void Main(string[] args)
        {
            InitWorld();

            Console.WriteLine("Press any key to start game.");
            Console.WriteLine("Press Enter to exit game.");

            var currentFrameNumber = 0;

            while (Console.ReadKey().Key != ConsoleKey.Enter)
            {
                Console.WriteLine("--------------------------------");

                _blackboard.EnemyIsNear = GetRandomBoolean();
                _blackboard.EnemyIsLessPowerful = GetRandomBoolean();
                _blackboard.EnergyIsLow = currentFrameNumber % 5 == 0;

                if (_robotAI.TaskStatus == TaskStatus.Ready)
                {
                    _robotAI.Run(_blackboard);
                }

                Console.WriteLine("End of frame.");
                Console.WriteLine("Press any key to calculate next frame.");
                Console.WriteLine("Press Enter to exit game.");
                Console.WriteLine("--------------------------------");

                currentFrameNumber++;
            }

            Console.WriteLine("Exiting game...");
            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }

        static void InitWorld()
        {
            _blackboard = new Blackboard();
            _robotAI = new RobotBehaviorSelector();
        }

        static bool GetRandomBoolean()
        {
            _random = new Random();

            return _random.Next(0, 2) == 0;
        }
    }
}
